fix(clickhouse): escape SQL identifiers and literals in metadata/DDL paths (#1914) - #2174
Merged
Merged
Conversation
Contributor
Author
|
Converting to draft: final adversarial review pass is still in progress for this branch. Will mark ready for review once it completes. (process note: PR was opened prematurely by automation) |
HandSonic
force-pushed
the
fix/sqli-clickhouse
branch
2 times, most recently
from
July 26, 2026 10:19
8ac520b to
9bcd7e9
Compare
HandSonic
marked this pull request as ready for review
July 26, 2026 10:28
This was referenced Jul 27, 2026
openai0229
force-pushed
the
fix/sqli-clickhouse
branch
from
July 29, 2026 07:28
c8332c7 to
5684d01
Compare
openai0229
approved these changes
Jul 29, 2026
openai0229
left a comment
Contributor
There was a problem hiding this comment.
Maintainer review complete. Identifier round-trip, expression guards, qualified DDL paths, and parameterized ALTER behavior are covered by the 43-test ClickHouse suite; the full 9-module reactor passes.
…ock enum dash rejection (OtterMind#1914)
…r per maintainer review (OtterMind#1914) - new ClickHouseIdentifierProcessor (SPI ISQLIdentifierProcessor): quoteIdentifier with backtick doubling, escapeString with backslash + single-quote doubling - ClickHouseMetaData overrides getSQLIdentifierProcessor(); metadata call sites use it - builders/managers/enums use ClickHouseIdentifierProcessor.INSTANCE - non-escapable validation moved to ClickHouseSqlGuards (column type expressions, engine whitelist, column default expressions) - ClickHouseSqlEscapes removed; tests migrated (24 green)
…-quote for DDL paths (OtterMind#1914) - quoteIdentifier(String) is conditional again: null/blank pass through, plain non-keyword identifiers stay unquoted, everything else is wrapped in backticks with embedded backticks doubled; versioned overload delegates - new quoteIdentifierAlways(String) carries the old unconditional semantics for DDL-generation call sites migrated from ClickHouseSqlEscapes - quoteIdentifierIgnoreCase stays the always-quote, case-preserving variant - override removeIdentifierQuote/isQuoteIdentifier so backtick-quoted identifiers round-trip through completion/matching consumers - add ClickHouse reserved keyword set used by the conditional check - tests cover conditional vs always behavior incl. null passthrough (30 green)
openai0229
force-pushed
the
fix/sqli-clickhouse
branch
from
July 29, 2026 07:38
5684d01 to
f73da33
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue
Part of #1914. This PR handles the ClickHouse plugin.
Summary
ClickHouseIdentifierProcessoras the plugin's identifier and string-literal processor. Conditional SPI quoting remains conditional, generated DDL uses an explicit always-quote path, embedded backticks round-trip correctly, and reserved-word matching is locale-independent.database.tableform, preferschemaName, and consistently qualify drop, truncate, and copy operations.Enum8('a' = -1),DateTime64(3, 'Asia/Shanghai'),Distributed(cluster, db, table, cityHash64(id)), andtoDateTime64(now(), 3)is preserved without re-encoding serialized literals.ALTER TABLE, emit valid rename/modify actions, and map schema create/drop operations to ClickHouseCREATE/DROP DATABASE.Affected surfaces
Verification
rtk mvn -B -pl chat2db-community-plugins/chat2db-community-clickhouse -am -f chat2db-community-server/pom.xml -Dmaven.test.skip=false -DskipTests=false -Dsurefire.failIfNoSpecifiedTests=false -Dmaven.test.failure.ignore=false clean testcompleted withBUILD SUCCESSacross all 9 reactor modules. ClickHouse tests: 43 passed; MySQL dependency-module tests: 653 passed; failures/errors/skips: 0.ALTER TABLEtypes, nested engine/default expressions, quoted literals, and rejection of unbalanced or multi-statement expressions.Risk and compatibility
Reviewer map
ClickHouseIdentifierProcessor,ClickHouseSqlGuards,ClickHouseSqlBuilder, andClickHouseIdentifierProcessorTest.Contributor declaration
AI assistance: Maintainer review, implementation refinements, test expansion, and PR description updates used AI coding assistance.